<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>把url的参数转化为一个对象</title>
</head>
<body>
  <script>
    function getQuery(url) {
      const index = url.indexOf('?');
      const obj = {};
      if(index === -1) return obj;
      const queryStr = url.slice(index + 1);
      const arr = queryStr.split('&');
      for(item of arr) {
        const keyValue = item.split('=');
        obj[keyValue[0]] = keyValue[1]
      }
      return obj;
    }
  </script>
</body>
</html>